<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%String path = request.getContextPath();%>
<script type="text/javascript" src="<%=path%>/projectjs/ImageFileUpload.js"></script>
<script type="text/javascript">
var flag_card_entity;
var sel_type=null;
var iu1=null;
function showRadioDiv(val) {
	for (var i = 0; i <= 4; i++) {
		if (val == i)
			$("#link_type_div_"+i).css("display", "block");
		else {
			$("#link_type_div_"+i).css("display", "none");
		}
		$("#link_type_inp_"+i).val("");
	}
	$("input[name='advertisingVO.linkId']").val("");
}
function getCardEntityByCustomer(customerId) {
	$.ajax({cache:false, url:"${pageContext.request.contextPath}/ajax/ajaxGetCardEntityByCustomerAndRand.do", type:"post", dataType:"json", data:{customerId:customerId}, success:handleResult});
}
function handleResult(json) {
	if (json==null) {
		alert("您选择的商家暂时没有可用的会员卡，请重新选择商家！");
		flag_card_entity = false;
	} else {
		$("input[name='advertisingVO.linkId']").val(json.id);
		flag_card_entity = true;
	}
}
function setAdvertisingVOValue(obj) {
	var vals = $("input[name='advertisingVO.linkType']:checked").val();
	if (vals == null) {
		alert("请选择链接类型！");
		return false;
	}
	var current_inp = $("#link_type_inp_"+vals);
	if ($(current_inp).val() == "") {
		alert($(current_inp).attr("tit"));
		if (vals == 4)
			$(current_inp).focus();
		else
			$("#a_link_id_look_"+vals).click();
		return false;
	}
	if (!iu1.validate()) {
		alert("您还有像素为：【"+iu1.need_add_pic_pixel.join(",")+"】的图片要添加，请添加图片！");
		iu1.openAddImgFrame();
		return false;
	}
	if (vals == 4) {
		$("input[name='advertisingVO.linkUrl']").val($(current_inp).val());
	}else if(vals==2) {
		if(!flag_card_entity){
			alert("您选择的商家暂时没有可用的会员卡，请重新选择商家！");
			return false;
		}
	}
	for (var i = 0; i <= 4; i++) {
		$("#link_type_inp_"+i).attr("name","");
	}
	return validateCallback(obj, navTabAjaxDone);
}
function changeSelType(val,w_h){
	if(sel_type!=null&&sel_type==val)return;
	sel_type=val;
	if(iu1!=null){
		$("#pic_content_div"+iu1.el_suffix).html("");
	}
	iu1 = new ImageUpload("","advertising","1","${pageContext.request.contextPath}","advertisingVO.picNames",w_h);
}
</script>
	<div class="pageContent">
		<form method="post" action="<%=path%>/advertising/saveAdvertising.action" class="pageForm required-validate" onsubmit="return setAdvertisingVOValue(this);">
			<input type="hidden" name="advertisingVO.linkUrl"/>
			<input type="hidden" name="advertisingVO.linkId"/>
			<div class="pageFormContent" layoutH="56" style="width: 98%">
				<p style="width: 48%">
					<label>广告标题：</label>
					<input type="text" name="advertisingVO.title" class="required"/>
				</p>
				<p style="width: 50%">
					<label>广告状态：</label>
					<input type="radio" name="advertisingVO.state" value="0"/>暂停
					<input type="radio" name="advertisingVO.state" value="1" checked="checked"/>正常
				</p>
				<p style="width: 48%">
					<label>广告位置：</label>
					<input type="radio" name="advertisingVO.zone" value="0" checked="checked" onclick="changeSelType(this.value,'640_660,800_825');"/>首页
					<input type="radio" name="advertisingVO.zone" value="1" onclick="changeSelType(this.value,'640_176,800_216');"/>轮换
				</p>
				<p style="width: 50%">
					<label>是否置顶：</label>
					<input type="radio" name="advertisingVO.top" value="1"/>是
					<input type="radio" name="advertisingVO.top" value="0" checked="checked"/>否
				</p>
				<div class="divider" style="border:0"></div>
				<p style="width: 100%;height: auto;float: none;">
					<label>链接类型：</label>
					<input type="radio" name="advertisingVO.linkType" value="0" onclick="showRadioDiv(this.value);"/>会员卡
					<input type="radio" name="advertisingVO.linkType" value="1" onclick="showRadioDiv(this.value);"/>优惠券
					<input type="radio" name="advertisingVO.linkType" value="2" onclick="showRadioDiv(this.value);"/>商家
					<input type="radio" name="advertisingVO.linkType" value="3" onclick="showRadioDiv(this.value);"/>活动
					<input type="radio" name="advertisingVO.linkType" value="4" onclick="showRadioDiv(this.value);"/>站外
					<div id="link_type_div_0" style="padding: 0;float: none;width:79%;padding-left: 145px;display: none">
						<label style="width:auto">会员卡：</label><input id="link_type_inp_0" name="advertisingVO.cardName" type="text" style="width:150px" readonly="readonly" tit="请选择会员卡！"/>
						<a id="a_link_id_look_0" class="btnLook" href="<%=path%>/cardEntity/listCardEntity.action?searchType=advertising" lookupGroup="advertisingVO"></a>
					</div>
					<div id="link_type_div_1" style="padding: 0;float: none;width:79%;padding-left: 210px;display: none;">
						<label style="width:auto">优惠券：</label><input id="link_type_inp_1" name="advertisingVO.favourableName" type="text" style="width:150px" readonly="readonly" tit="请选择优惠券！"/>
						<a id="a_link_id_look_1" class="btnLook" href="<%=path%>/favourableEntity/listFavourableEntity.action?searchType=advertising" lookupGroup="advertisingVO"></a>
					</div>
					<div id="link_type_div_2" style="padding: 0;float: none;width:40%;padding-left: 270px;display: none;">
						<label style="width:auto">商家：</label><input id="link_type_inp_2" name="advertisingVO.customerName" type="text" style="width:150px" readonly="readonly" tit="请选择商家！"/>
						<a id="a_link_id_look_2" class="btnLook" href="<%=path%>/customer/listCustomer.action?searchType=advertising" lookupGroup="advertisingVO"></a>
					</div>
					<div id="link_type_div_3" style="padding: 0;float: none;width:40%;padding-left: 320px;display: none;">
						<label style="width:auto">活动：</label><input id="link_type_inp_3" name="advertisingVO.activeTitle" type="text" style="width:150px" readonly="readonly" tit="请选择活动！"/>
						<a id="a_link_id_look_3" class="btnLook" href="<%=path%>/active/listActive.action?searchType=advertising" lookupGroup="advertisingVO"></a>
					</div>
					<div id="link_type_div_4" style="padding: 0;float: none;width:50%;padding-left: 375px;display: none">
						站外地址：<input id="link_type_inp_4" type="text" style="float:none;width:240px" tit="请输入站外地址！"/>
					</div>
				</p>
				<div class="divider" style="border:0"></div>
				<p style="width: 100%">
					<label>广告图片：</label>
					<a class="button" onclick="openAddImgFrame(1);"><span>添加图片</span></a>
					<a id="add_pic_a_id1" class="btnAttach" href="<%=path%>/jsp/common/image_file_upload.jsp" lookupGroup="" width="560" height="300" style="display: none"></a>
					<div class="divider" style="border:0"></div>
					<div id="pic_need_add_pixel_div1"></div>
					<div class="divider" style="border:0"></div>
					<div id="pic_content_div1" style="float: none;width:auto;padding-left: 150px;"></div>
				</p>
			</div>
			<div class="formBar">
				<ul>
					<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
					<li>
						<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
					</li>
				</ul>
			</div>
		</form>
	</div>
<script type="text/javascript">changeSelType(0,"640_660,800_825");</script>